#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>

int main() {

    char a[1000] = "32 01 00 AE 90 02 00 01 02 30 03 00 AB 32 31 31 02 00 32 33 33 01 00 CC";
    
    char* target = "31";  
    char* tvl[1000];
    int tvlLen = 0;
    char* p = strtok(a, " ");
    while (p != NULL) {
        tvl[tvlLen++] = p;
        // printf("%s\t", p);
        p = strtok(NULL, " ");
    }
    
    char* res[1000];
    int resLen = 0, i = 0;
    memset(res, 0, sizeof(char*) * 1000);

    while (i < tvlLen) {
        char* token = tvl[i];
        int len = atoi(tvl[i + 2]) + atoi(tvl[i + 1]);
        // printf("%d, %s, %d\t", i, token, len);
        if (strcmp(target, token) == 0) {
            for (int j = 1; j < len + 1; ++j) {
                res[resLen++] = tvl[i + j + 2];
            }
        }
        i = i + len + 3;
        
    }


    for (int i = 0; i < resLen; ++i) {
        printf("%s ", res[i]);
    }
    
    // printf("%s", res);
    return 0;
}